***Syntax Terrorism and Immigration Policy Preferences

*RECODING
*Terrorism treatment
gen country_terror=.
replace country_terror=1 if v_terror==1
replace country_terror=0 if v_terror==0
gen outside_terror=.
replace outside_terror=1 if v_terror==2
replace outside_terror=0 if v_terror==0

*Education
gen higheduc=.
replace higheduc = 1 if v_5_uk==5 & country==2
replace higheduc = 0 if v_5_uk<5 & country==2

replace higheduc = 1 if v_5_de==5 & country==1
replace higheduc = 0 if v_5_de<5 & country==1

*Fearfulness
alpha f_dark f_vand, gen(secatt1)
alpha f_secsur f_govsaf, gen(secatt2)

*Integration policies
recode d_intgpol 1=4 2=3 3=2 4=1, gen(intgpol_rec)


*ANALYSES
*Table 1: Terrorism and immigration policy preferences
reg d_immigpol ib0.v_terror i.country
est store m1
reg d_immigpol ib0.v_terror##c.secatt1 i.country
est store m2
reg d_immigpol ib0.v_terror##c.secatt1 male higheduc v_4 i.country 
est store m3
reg d_immigpol i.v_neglect i.country if v_terror==1 
est store m4
reg d_immigpol i.v_neglect i.country if v_terror==2
est store m5

*FIGURE 1: Marginal Effect of Terrorism on Anti-Immigrant Policy Preferences for Different Levels of Fearfulness
est restore m2
margins, dydx(i.v_terror) at(secatt1=(1 2 3 4))

gen x =_n
replace x = . if x>4

gen beta_country=.
gen lower_country=.
gen upper_country=.

capture matrix drop marg
matrix def marg=r(b)
replace beta_country= marg[1,5] if x==1
replace beta_country= marg[1,6] if x==2
replace beta_country= marg[1,7] if x==3
replace beta_country= marg[1,8] if x==4

capture matrix drop confd
matrix def confd=r(table)

replace lower_country= confd[5,5] if x==1
replace lower_country= confd[5,6] if x==2
replace lower_country= confd[5,7] if x==3
replace lower_country= confd[5,8] if x==4

replace upper_country= confd[6,5] if x==1
replace upper_country= confd[6,6] if x==2
replace upper_country= confd[6,7] if x==3
replace upper_country= confd[6,8] if x==4

graph twoway (scatter beta_country x, yaxis(1) lp(solid) msymbol(circle) msize(small)  ///
 graphregion(color(white)) legend(off) title("Country terrorism", size(small)) ///
 xtitle("Fearfulness", size(small)) xlabel(#4, valuelabel labsize(2.5)) yline(0) ylabel(-0.3 0 0.3, labsize(2.5) axis(1)) ///
 ytitle(Effect terrorism treatment, size(3))) ///
 (rspike lower_country upper_country x, lcolor(black) vertical name(A, replace))

 
gen beta_outside=.
gen lower_outside=.
gen upper_outside=.

replace beta_outside= marg[1,9] if x==1
replace beta_outside= marg[1,10] if x==2
replace beta_outside= marg[1,11] if x==3
replace beta_outside= marg[1,12] if x==4

replace lower_outside= confd[5,9] if x==1
replace lower_outside= confd[5,10] if x==2
replace lower_outside= confd[5,11] if x==3
replace lower_outside= confd[5,12] if x==4

replace upper_outside= confd[6,9] if x==1
replace upper_outside= confd[6,10] if x==2
replace upper_outside= confd[6,11] if x==3
replace upper_outside= confd[6,12] if x==4

graph twoway (scatter beta_outside x, yaxis(1) lp(solid) msymbol(circle) msize(small)  ///
 graphregion(color(white)) legend(off) title("Terrorism outside Europe", size(small)) ///
 xtitle("Fearfulness", size(small)) xlabel(#4, valuelabel labsize(2.5)) yline(0) ylabel(-0.3 0 0.3, labsize(2.5) axis(1)) ///
 ytitle(Effect terrorism treatment, size(3))) ///
 (rspike lower_outside upper_outside x, lcolor(black) vertical name(B, replace))


graph combine A B, graphregion(color(white))
 

*APPENDIX
*Table A1: Descriptive statistics Germany
sum d_immigpol v_terror v_neglect secatt1 higheduc if country==1

*Table A2: Descriptive statistics UK
sum d_immigpol v_terror v_neglect secatt1 higheduc if country==2

*Table A4: Replication Table 1 in Germany only
reg d_immigpol ib0.v_terror if country==1
reg d_immigpol ib0.v_terror##c.secatt1 if country==1
reg d_immigpol ib0.v_terror##c.secatt1 male higheduc v_4 if country==1
reg d_immigpol i.v_neglect if v_terror==1 & country==1
reg d_immigpol i.v_neglect if v_terror==2 & country==1

*Table A5: Replication Table 1 in UK only
reg d_immigpol ib0.v_terror if country==2
reg d_immigpol ib0.v_terror##c.secatt1 if country==2
reg d_immigpol ib0.v_terror##c.secatt1 male higheduc v_4 if country==2
reg d_immigpol i.v_neglect if v_terror==1 & country==2
reg d_immigpol i.v_neglect if v_terror==2 & country==2

*Table A6: Interaction between Probability Treatment and Subjective Feelings of Fearfulness Predicting Anti-Immigrant Policy Preferences
reg d_immigpol i.v_neglect##c.secatt1 i.country if v_terror==1
reg d_immigpol i.v_neglect##c.secatt1 i.country if v_terror==2

*Table A7: Replication of Table 1 with Integration and Surveillance measures as Dependent Variable and Alternative Fearfulness Measure
recode d_survpol 1=4 2=3 3=2 4=1, gen(d_survpol_rec)
label var d_survpol_rec "agreement with more severe surveillance laws"
reg d_survpol_rec ib0.v_terror i.country
reg d_survpol_rec ib0.v_terror##c.secatt1 i.country 
reg d_survpol_rec i.v_neglect i.country if v_terror==1 
reg d_survpol_rec i.v_neglect i.country if v_terror==2
recode d_intgpol 1=4 2=3 3=2 4=1, gen(d_intgpol_rec)
label var d_intgpol_rec "agreement with new laws requiring immigrants to integrate better"
reg d_intgpol_rec ib0.v_terror i.country
reg d_intgpol_rec ib0.v_terror##c.secatt1 i.country 
reg d_intgpol_rec i.v_neglect i.country if v_terror==1 
reg d_intgpol_rec i.v_neglect i.country if v_terror==2
reg d_immigpol ib0.v_terror##c.secatt2 i.country
